{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.7d3b3ed27cc822cdbb32880d1af9399c.315360000.1926695928.282335-23578622', 'expires_in': 2592000, 'session_key': '9mzdXvLlwRBu8GIweKNfRfJOPEHD7th2sZDrvy6J/hgkV+Nkrzldxl8PbOSl12F+SwrH4Jl1tb8SX7IVO8mWiB4V6O/RAg==', 'access_token': '24.e7ce90df3a0d73812753565d5ab019ad.2592000.1613927928.282335-23578622', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_kg_cognitive_question wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': '5951eeb2a0e7ee4a38f9c46d1522309a'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=WNhGEQao00TE5Ou0oPD4hRLT&client_secret=N2oMEv7nc35Dp7rLXUjC8uPhswGgKgGj'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "'access_token': '24.6b12a38f725bd83248454b31a786b796.2592000.1613927771.282335-23578622'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'error_code': 17, 'error_msg': 'Open api daily request limit reached'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "url=\"https://aip.baidubce.com/rpc/2.0/kg/v1/cognitive/question\"\n",
    "#https://aip.baidubce.com/rpc/2.0/kg/v1/cognitive/question\n",
    "params={\n",
    "    \"query\":\"刘德华年龄\",\n",
    "    'access_token': '24.6b12a38f725bd83248454b31a786b796.2592000.1613927771.282335-23578622'\n",
    "}\n",
    "headers={\n",
    "    \"content-type\":\"application/json\"\n",
    "}\n",
    "r = requests.post(url,params=params,headers=headers)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.be77d03eef2fcc06fd41d90008b28c31.315360000.1926697667.282335-23578622', 'expires_in': 2592000, 'session_key': '9mzdCPOA/gdn/bJ0GkNlXb9TstTtjTKtaZeA1MmeqbeAla7spaqXfxkm0kbjcGPsGF0bQBJqiQEcR8iccl/4bctPNwxMTQ==', 'access_token': '24.3727a3f01009f4da6b38916d55b2f133.2592000.1613929667.282335-23578622', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_kg_cognitive_question wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': 'fbc1a7a386e84396741b178929c6daf7'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=WNhGEQao00TE5Ou0oPD4hRLT&client_secret=N2oMEv7nc35Dp7rLXUjC8uPhswGgKgGj'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'access_token': '24.3727a3f01009f4da6b38916d55b2f133.2592000.1613929667.282335-23578622'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 4557416950674192983, 'result': [{'score': 0.9389848709106445, 'name': '青苹果竹芋'}, {'score': 0.44104066491127014, 'name': '玉簪'}, {'score': 0.1332574486732483, 'name': '立叶蔓绿绒'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "植物识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/plant\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('zhiwu.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.3727a3f01009f4da6b38916d55b2f133.2592000.1613929667.282335-23578622'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.f534cf65eaa4b17c14c0fa1c7b0746b1.315360000.1926698012.282335-23578622', 'expires_in': 2592000, 'session_key': '9mzdCrakBRiiW5LN3Glq1qwe2C95kNxiWsF44SjIHbMPGeTSh/T3SdeknqOa+ehvSBkElicomGRuYXlmNoEhBWawhPEveQ==', 'access_token': '24.12069fb0f28e4603c60556eaa0e77a8d.2592000.1613930012.282335-23578622', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_kg_cognitive_question wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': '1f15abb845ecddafe03bbf28956a80c1'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=WNhGEQao00TE5Ou0oPD4hRLT&client_secret=N2oMEv7nc35Dp7rLXUjC8uPhswGgKgGj'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'access_token': '24.3727a3f01009f4da6b38916d55b2f133.2592000.1613929667.282335-23578622'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 2541168401091330679, 'result': [{'score': '0.430153', 'name': '英国短毛猫'}, {'score': '0.151259', 'name': '短毛猫'}, {'score': '0.113874', 'name': '英国长毛猫'}, {'score': '0.0577151', 'name': '波斯猫'}, {'score': '0.0436553', 'name': '金吉拉猫'}, {'score': '0.024551', 'name': '拿破仑猫'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "动物识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/animal\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('dongwu.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.3727a3f01009f4da6b38916d55b2f133.2592000.1613929667.282335-23578622'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
